package com.zjitc.common.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ${赵诚挚}
 * @Date: 2024/6/21 10:57
 */
@Data
@ApiModel("接口规范")
@Accessors(chain = true)
public class RespBean {
    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("提示信息")
    private String msg;

    @ApiModelProperty("数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    public RespBean(Integer code, String msg, Map<String, Object> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public RespBean() {

    }


    public static RespBean success() {
        return new RespBean().setCode(200);
    }

    public static RespBean error(Integer code, String msg) {
        return new RespBean().setCode(code).setMsg(msg);
    }

    public RespBean code(Integer code) {
        this.setCode(code);
        return this;
    }

    public RespBean msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public RespBean data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

    public RespBean data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

}